﻿using System;
using System.Linq;
using System.Reflection;

namespace BoldBrick.SharePoint.CommonControls.Extensions
{
	public static class EnumEx
	{
		public static TClass GetAttribute<TClass>(this Enum value) where TClass : Attribute
		{
			FieldInfo fieldInfo = value.GetType().GetField(value.ToString());

			TClass attribute = fieldInfo.GetCustomAttributes(typeof (TClass), false).FirstOrDefault() as TClass;
			return attribute;
		}
	}
}
